from redis import Redis, ConnectionPool

class RedisClient:
    _pool = None
    _redis = None
    myRedis = {
        'host': '127.0.0.1',
        'port': 6379,
        'db': 2,
        'password': '123456'
    }

    @classmethod
    def get_redis(cls):
        if cls._redis is None:
            if cls._pool is None:
                cls._pool = ConnectionPool(
                    host=cls.myRedis['host'],
                    port=cls.myRedis['port'],
                    db=cls.myRedis['db'],
                    password=cls.myRedis['password'],
                    decode_responses=True,  # 返回字符串而非字节
                    max_connections=50      # 可调大小
                )
            cls._redis = Redis(connection_pool=cls._pool)
        return cls._redis